home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / mus2v131.zip / ModTry.cmd < prev    next >
OS/2 REXX Batch file  |  1996-07-25  |  5KB  |  151 lines

  1. /* ########################################################################
  2.  
  3.    This REXX script will communicate with a running Module Player that
  4.    support a Command Pipe.
  5.  
  6.    The Following commands are supported by the interface,
  7.       Query Song  -- Returns three lines, first is the file name, second is the
  8.                      index and third is the song title. They represent
  9.                      the currently playing song.
  10.       Query NextSong -- Returns the file name and index of the next song
  11.       Query SongList -- Returns the # of items in the first line and each
  12.                         line after contains 1 item from the song list.
  13.       Query LoopStyle -- Returns the current loop style,
  14.                          param 1 = Normal, 2 = Non looped, 3 = inifite
  15.                          loop
  16.       Query Server -- Returns TRUE if Player is in server mode, (TRUE,FALSE)
  17.       Play Next -- Plays the next song
  18.       Play Last -- Plays the last song
  19.       Play Pause -- Pause play back
  20.       Play Resume -- Resume play back
  21.       Play Index -- Jumps to the given index in the song list and plays,
  22.                     returns 1 line, the filename
  23.       Play Song -- Searches the song list for the given substring match,
  24.                    first one is played and the name and index are returned.
  25.       Set LoopStyle -- Sets the current loop style, argument is 0,1,2
  26.       Set Server -- Set server mode, 0,1,FALSE,TRUE
  27.       SongList Add -- Add items to the song list (at the end), ie
  28.                         SongList Add *.mod *.s3m
  29.                       Returns the new size of the list
  30.       SongList Erase -- Nukes the entire song list
  31.       SongList EraseIndx -- Nukes 1 item in the list (by index)
  32.       Exit -- Terminate the player
  33.  
  34.    ########################################################################
  35. */
  36. '@echo off'                       /* Don't echo commands */
  37. say " REXX Module Command Pipe Tester V1.0                                     Ethos"
  38.    call OpenPlayer
  39.    if Result <> 0 then do
  40.       say "Error" Error
  41.       return
  42.    end
  43.    say "Command pipe opened to" Type || ". Command set Version" Version
  44.    say "Type quit to exit"
  45.  
  46.    do while (1)
  47.       Line = linein();
  48.       if translate(Line) = "QUIT" then return
  49.  
  50.       parse var Line A B C
  51.  
  52.       if CallPlayer(A,B,C) <> 0 then do
  53.          say "Error" Error
  54.          iterate;
  55.       end
  56.  
  57.       if Result.0 > 1 then
  58.          say "---"
  59.       else
  60.          say "Ok"
  61.       I = 1;
  62.       do while (I <= Result.0)
  63.          say Result.I
  64.          I = I + 1
  65.       end
  66.  
  67.       if Result.0 > 1 then
  68.          say "---"
  69.  
  70.       if translate(Line) = "EXIT" then return
  71.    end
  72. return
  73.  
  74. /* ########################################################################
  75.  
  76.    Function - CallPlayer
  77.    Eg - if (CallPlayer("Query","Song","") <> 0) then Error
  78.  
  79.    Description - This procedure sends a command message to the player.
  80.                  An error is returned if the player doesn't understand
  81.                  the message or something else is wrong.
  82.                    Result - A stem containing each line of the result
  83.                    Error - Global error code
  84.  
  85.    ########################################################################
  86. */
  87. CallPlayer: procedure expose Result. Player Error
  88.    parse arg Command, SCommand, Arg
  89.  
  90.    Error = ""
  91.    Result.0 = 0
  92.  
  93.    /* Player not loaded */
  94.    if (Player = "") then do
  95.       Error = "Player not Inited"
  96.       return 1
  97.    end
  98.  
  99.    call lineout Player,Command SCommand Arg
  100.  
  101.    /* Get all the results */
  102.    do while (1)
  103.       Line = linein(Player)
  104.  
  105.       /* Error or something */
  106.       if (pos("!!",Line) = 1) then do
  107.          if (Line = "!! OK") then
  108.             return 0
  109.          Error = substr(Line,4)
  110.          return 1
  111.       end;
  112.  
  113.       Result.0 = Result.0 + 1
  114.       I = Result.0
  115.       Result.I = Line
  116.    end
  117.  
  118. return 0
  119.  
  120. /* ########################################################################
  121.  
  122.    Function - OpenPlayer
  123.    Eg - call OpenPlayer
  124.  
  125.    Description - This procedure opens the pipe and sets the following:
  126.                    Player - The name of the pipe - \pipe\Player
  127.                    Version - The pipe comminication version
  128.                    Type - The program running on the other end, 'Text UI'
  129.                    Error - Global Error Code
  130.  
  131.    ########################################################################
  132. */
  133. OpenPlayer:procedure expose Player Version Type Error
  134.    Error = ""
  135.  
  136.    Result = Stream("\pipe\ModulePlayer","C","OPEN");
  137.    if (Result <> "READY:") then do
  138.       Error = "Unable to communicate with the  Player, is it running?"
  139.       Player = ""
  140.       return 1
  141.    end
  142.    Player = "\pipe\ModulePlayer"
  143.  
  144.    /* Get the version */
  145.    S = linein(Player)
  146.    say S
  147.    parse var S 'V' Version .
  148.    Type = linein(Player)
  149.    say Type
  150. return 0
  151.